package user

import (
	"context"

	"github.com/gogf/gf/v2/os/gtime"
	"github.com/gogf/gf/v2/util/gconv"

	v1 "gf-xb-api/api/user/v1"
	"gf-xb-api/internal/model/dto"
	"gf-xb-api/internal/service"
)

func (c *ControllerV1) Update(ctx context.Context, req *v1.UpdateReq) (res *v1.UpdateRes, err error) {

	// 参数转换
	var in *dto.UserUpdateInput

	// 时间戳 -> 时间
	err = gconv.Struct(req, &in)
	if err != nil {
		return nil, err
	}

	in.UpdatedAt = gtime.NewFromTimeStamp(req.Timestamp)

	output, err := service.User().Update(ctx, in)
	if err != nil {
		return nil, err
	}

	return (*v1.UpdateRes)(&output), nil
}
